import {format} from 'date-fns';
import moment from "moment/moment";

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm';
const DATE_FORMAT = 'YYYY-MM-DD';
const DAY_FORMAT = 'D';

export function formatToDateTime(date: Date | number, formatStr = DATE_TIME_FORMAT): string {
  return format(date, formatStr);
}

export function formatToDate(date: Date | number, formatStr = DATE_FORMAT): string {
  return format(date, formatStr);
}

export function nearlyDays(amount: number = 7) {
  return moment().subtract(amount, 'days').format(DATE_FORMAT);
}

export function nearlyMonth() {
  return moment().subtract(1, 'months').format(DATE_FORMAT);
}

export function currentDate() {
  return moment().format(DATE_FORMAT);
}

export function nearlyDay(amount: number) {
  return moment().subtract(amount, 'days').format(DATE_FORMAT);
}

export function formatdate(dt) {
  return moment(dt).format(DAY_FORMAT);
}
